package com.smartlink.dao;

import java.util.List;

import org.hibernate.Session;
import org.hibernate.SessionFactory;

import com.smartlink.pojo.Sensors;

public class SensorsDaoImpl implements Dao<Integer, Sensors> {
	private SessionFactory sessionFactory;
	private Session session;

	public Session getSession() {
		session = sessionFactory.getCurrentSession();
		return session;
	}

	public void setSessionFactory(SessionFactory sessionFactory) {
		this.sessionFactory = sessionFactory;
	}

	@Override
	public boolean insert(Sensors v) {
		// TODO Auto-generated method stub
		getSession().save(v);
		return true;
	}

	@Override
	public boolean delete(Sensors v) {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public boolean deleteById(Integer k) {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public boolean update(Sensors v) {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public Sensors findById(Integer k) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public List<Sensors> getAll() {
		// TODO Auto-generated method stub
		String hql = "FROM Sensors";
		@SuppressWarnings("unchecked")
		List<Sensors> list = getSession().createQuery(hql).list();
		return list;
	}

	public List<Sensors> getAll(int clsroomId) {
		// TODO Auto-generated method stub
		String hql = "FROM Sensors WHERE classroom=? ORDER BY id ";
		@SuppressWarnings("unchecked")
		List<Sensors> list = getSession().createQuery(hql).setInteger(0, clsroomId).list();
		return list;
	}

	public List<Sensors> getSensorByType(int clsroomId, int type) {
		String hql = "FROM Sensors WHERE classroom=? AND type=?";
		@SuppressWarnings("unchecked")
		List<Sensors> sensorList = getSession().createQuery(hql).setInteger(0, clsroomId).setInteger(1, type).list();
		return sensorList;
	}

	@Override
	public List<Sensors> getAll(Integer currentIndex, Integer pageSize) {
		// TODO Auto-generated method stub
		return null;
	}

}
